#pragma once

#include "SPEmitter.h"

namespace SP
{
	class DLL_EXPORT SPEmitterBeam : public SPEmitter
	{
	public:
		enum BEAM_SHAPE
		{
			BS_POINT = 0,
			BS_LINE,
			BS_CURVE,
			BS_CIRCLE
		};

		struct VERTEX
		{
			XMFLOAT3 vCtrlPos;
			XMFLOAT3 vSrcPos;
		};

		SPEmitterBeam();
		SPEmitterBeam( SPEmitterBeam* archetype );
		~SPEmitterBeam();

		void Create( SPEmitterBeam* archetype );

		virtual void Initialize();
		virtual void Render();
		virtual void Advance( float fElapsedTime );
		virtual void ClearModule();
		virtual void CreateFileBuffer( SPFileBuffer* );
		virtual void CreateFromFileBuffer( BYTE* );
		virtual bool SetSPModule( SPModule* pModule );

		HRESULT Create( UINT nNumControlPoint );
		void Reshape();

		void SetTessellationAmount( UINT nAmount ){ m_nTessellationAmount = nAmount; }
		void UpdatePerFrame( BOOL bUpdate ){ m_bUpdatePerFrame = bUpdate; }
		void EnableNoise( BOOL bEnable ){ m_bEnableNoise; }
		void FaceToCamera( BOOL bFaceToCamera ){ m_bFaceToCamera = bFaceToCamera; }
		void SetWidthScale( FLOAT ws ){ m_fWidthScale = ws; }
		void SetNoise( FLOAT fSpeed, FLOAT fScale )
		{ 
			m_fNoiseSpeed = fSpeed; 
			m_fNoiseScale = fScale;
		}
		HRESULT CreateTextureFromFile( const wchar_t* file );

	private:
		void Release();

		void ReshapePoint();
		void ReshapeLine();
		void ReshapeCurve();
		void ReshapeCircle();

		UINT m_nNumControlPoint;
		UINT m_nTessellationAmount;
		UINT m_nNumVertices;

		BOOL m_bUpdatePerFrame;
		BOOL m_bFaceToCamera;
		BOOL m_bEnableNoise;
		FLOAT m_fWidthScale;

		SPModuleBeamSource* m_pModuleSource;
		SPModuleBeamTarget* m_pModuleTarget;
		SPModuleBeamShape* m_pModuleShape;

		XMFLOAT3* m_pControlPoint;
		ID3D11ShaderResourceView* m_pSRVControlPoint;
		ID3D11UnorderedAccessView* m_pUAVPerlinSeed;
		ID3D11UnorderedAccessView* m_pUAVVertex;

		void SetZero();

		ID3D11Buffer* m_pControlPointBuffer;
		ID3D11Buffer* m_pPerlinSeedBuffer;	
		ID3D11Buffer* m_pVertexBuffer;			

		FLOAT m_fNoiseScale;
		FLOAT m_fNoiseSpeed;

		// Texture
		ID3D11Resource*						m_pTex;
		ID3D11ShaderResourceView*	m_pTexSRV;

		friend class SPEmitterBeamAdvencer;
		friend class SPEmitterBeamRenderer;
	};
}

